package proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;

public class Client {
    public static void main(String[] args) {
       final producer producer=new producer();
        Iproducer proxyproducter=
                (Iproducer) Proxy.newProxyInstance(producer.getClass().getClassLoader()
                , producer.getClass().getInterfaces(), new InvocationHandler() {
                    @Override
                    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                        if ("sale".equals(method.getName())) {
                            float money =
                                    (float) ((float) args[0] * 0.8);
                            return method.invoke(producer, money);
                        }
                        else if ("after".equals(method.getName()))
                            return method.invoke(producer,
                                    (float)((float)args[0] * 0.01));
                        return null;
                    }
                });
        proxyproducter.after(5000);
    }
}
